package com.open.api.wechat.common;

import com.open.api.wechat.utils.JsonUtil;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author : zhaoxuan
 * @version : 1.0
 * @date : 2021/6/30 23:39
 * @description : WeChatRequest
 */
public abstract class WeChatCommonRequest<T extends WeChatCommonResponse> {

    public static final String ACCESS_TOKEN = "ACCESS_TOKEN";

    @Setter
    private String url;

    public abstract String getDefaultUrl();

    public String getUrl(){
        return StringUtils.isNotBlank(url) ? url : getDefaultUrl();
    }

    public String getUrl(String accessToken){
        String url = getUrl();
        return url.contains(ACCESS_TOKEN) ? url.replace(ACCESS_TOKEN, accessToken) : url;
    }

    public Object getCondition(){
        return null;
    }

    public String getBody(){
        Object condition = getCondition();
        return condition == null ? "" : JsonUtil.toJsonString(condition);
    }

    public HttpMethod getMethod(){
        return HttpMethod.GET;
    }

    public abstract Class<T> getResponse();
}
